package com.rjxy.plansystemmanagement.controller.entityController;

import com.rjxy.plansystemmanagement.entity.Result.Result;
import com.rjxy.plansystemmanagement.entity.RoomInformation;
import com.rjxy.plansystemmanagement.service.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Rooms")
public class RoomController {
    @Autowired
    private RoomService roomService;
    @GetMapping
    public Result list(){
        log.info("查询所有客房");
        List<RoomInformation> roomInformationList = roomService.list();
        return Result.success(roomInformationList);
    }


    @GetMapping("/{ID}")
    public Result getRoomById(@PathVariable Integer ID){
        log.info("根据id{}查询客房");
        RoomInformation roomInformation = roomService.getRoomById(ID);
        return Result.success(roomInformation);
    }

    @GetMapping("/HotelId/{id}")
    public Result getRoomByHotelId(@PathVariable Integer id){
        log.info("根据酒店id{}查询客房",id);
        List<RoomInformation> roomInformationList = roomService.getRoomByHotelId(id);
        return Result.success(roomInformationList);
    }



    @DeleteMapping("/{ID}")
    public Result deleteRoom(@PathVariable Integer ID){
        log.info("根据RoomID{}删除指定订单", ID);
        roomService.deleteRoom(ID);
        return Result.success();
    }


    @PostMapping
    public Result addRoom(@RequestBody RoomInformation roomInformation) throws ParseException {
        log.info("增加客房");
        roomService.addRoom(roomInformation);
        return Result.success();
    }

    @PutMapping
    public Result updateRoom(@RequestBody RoomInformation roomInformation){
        log.info("更新id{}的客房信息",roomInformation.getID());
        roomService.updateRoom(roomInformation);
        return Result.success();
    }

}

